package com.llgz.hotelmanageapi.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.llgz.hotelmanageapi.common.CommonResult;
import com.llgz.hotelmanageapi.pojo.DO.*;
import com.llgz.hotelmanageapi.pojo.DO.ConsumptionInfo;
import com.llgz.hotelmanageapi.pojo.DO.ConsumptionInfo;
import com.llgz.hotelmanageapi.service.impl.ConsumptionInfoServiceImpl;
import com.llgz.hotelmanageapi.service.impl.ConsumptionInfoServiceImpl;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 客户消费表 前端控制器
 * </p>
 *
 * @author Bernie_fang
 * @since 2021-07-19
 */
@RestController
@RequestMapping("/consumptionInfo")
@RequiresRoles(value = {"root", "admin", "manager", "reception"}, logical = Logical.OR)
public class ConsumptionInfoController {
    @Autowired
    ConsumptionInfoServiceImpl consumptionInfoService;

    /**
     * @MethodName addConsumptionInfo
     * @Params * @param ConsumptionInfo
     * @Description 添加
     * @Return CommonResult
     */
    @PostMapping("/addConsumptionInfo")
    @ApiOperation(value = "添加", response = CommonResult.class, httpMethod = "POST")
    public CommonResult addConsumptionInfo(@RequestBody ConsumptionInfo consumptionInfo){
        boolean save = consumptionInfoService.save(consumptionInfo);
        return CommonResult.successResponse(save);
    }
    /**
     * @MethodName getConsumptionInfoList
     * @Params * @param ConsumptionInfo
     * @Description 查找全部
     * @Return CommonResult
     */
    @GetMapping("/getConsumptionInfoList")
    @ApiOperation(value = "查找", response = CommonResult.class, httpMethod = "GET")
    public CommonResult getConsumptionInfoList(@RequestParam String query,@RequestParam Integer pageNum,@RequestParam Integer pageCount){
        QueryWrapper<ConsumptionInfo> queryWrapper = new QueryWrapper<>();
        queryWrapper.orderByDesc("modified_time");
        if (query != null && !query.isEmpty()){
            queryWrapper.like("",query);
        }
        IPage<ConsumptionInfo> page = consumptionInfoService.page(new Page<>(pageNum, pageCount), queryWrapper);
        return CommonResult.successResponse(page);
    }
    @GetMapping("/getConsumptionInfoById")
    @ApiOperation(value = "查找(Id)", response = CommonResult.class, httpMethod = "GET")
    public CommonResult getConsumptionInfoById(@RequestParam String id){
        ConsumptionInfo category = consumptionInfoService.getOne(new QueryWrapper<ConsumptionInfo>().eq("id", id));
        return CommonResult.successResponse(category);
    }
    /**
     * @MethodName updateConsumptionInfo
     * @Params * @param ConsumptionInfo
     * @Description 更新
     * @Return CommonResult
     */
    @PostMapping("/updateConsumptionInfo")
    @ApiOperation(value = "更新", response = CommonResult.class, httpMethod = "POST")
    public CommonResult updateConsumptionInfo (@RequestBody ConsumptionInfo consumptionInfo){
        boolean b = consumptionInfoService.updateById(consumptionInfo);
        return CommonResult.successResponse(b);
    }
//    /**
//     * @MethodName deleteConsumptionInfo
//     * @Params * @param ConsumptionInfo
//     * @Description 删除
//     * @Return CommonResult
//     */
//    @PostMapping("/deleteConsumptionInfo")
//    @ApiOperation(value = "删除", response = CommonResult.class, httpMethod = "POST")
//    public CommonResult deleteConsumptionInfo (@RequestParam String id){
//        boolean b = consumptionInfoService.removeById(id);
//        return CommonResult.successResponse(b);
//    }
    /**
     * @MethodName deleteConsumptionInfo
     * @Params * @param ConsumptionInfo
     * @Description 删除（多选）
     * @Return CommonResult
     */
    @PostMapping("/deleteConsumptionInfo")
    @ApiOperation(value = "删除（多选）", response = CommonResult.class, httpMethod = "POST")
    public CommonResult deleteConsumptionInfo (@RequestBody List<String> ids){
        boolean b = consumptionInfoService.removeByIds(ids);
        return CommonResult.successResponse(b);
    }
}

